package com.zy.Conterller;

import com.zy.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
@Slf4j
public class GlobalExcptionCatch {
    /**
     * 全局异常扑捉
     * @param ex
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public ResultVo errorHandler(RuntimeException ex){
        if (ex instanceof UnauthorizedException){
            log.error("用户无此权限",ex);
        }else{
            log.error(ex.getMessage(),ex);
        }

        return ResultVo.fail("查询操作失败",ex);
    }
 /*   @ExceptionHandler(NonTransientDataAccessException.class)
    public ResultVo error(NonTransientDataAccessException ex){
        if (ex instanceof DataIntegrityViolationException){
            log.error("不能添加空",ex);
        }else{
            log.error(ex.getMessage(),ex);
        }


        return ResultVo.fail("不能空值添加,请重新输入!!");
    }*/
   /* @ExceptionHandler(NestedRuntimeException.class)
    public  ResultVo Rea(NestedRuntimeException ex){
        if (ex instanceof HttpMessageConversionException){

        }else{
            log.error(ex.getMessage(),ex);
        }
        return ResultVo.fail("请清楚使用字母和数字");
    }*/
}
